import 'dart:core';

class ProductTemplate {
  String? id;
  String? name;
  String? description;
  String? categId;
  String? categName;
  String? defaultCode;
  String? uomId;
  String? uomName;
  num? density;
  num? sequence;
  String? remark;
  String? createUid;
  String? createName;
  String? createDate;
  String? writeUid;
  String? writeName;
  String? writeDate;
  String? code;

  ProductTemplate({
    this.id,
    this.name,
    this.description,
    this.categId,
    this.categName,
    this.defaultCode,
    this.uomId,
    this.uomName,
    this.density,
    this.sequence,
    this.remark,
    this.createUid,
    this.createName,
    this.createDate,
    this.writeUid,
    this.writeName,
    this.writeDate,
    this.code,
  });

  ProductTemplate copyWith({
    String? id,
    String? name,
    String? description,
    String? categId,
    String? defaultCode,
    String? createUid,
    String? createDate,
  }) {
    return new ProductTemplate(
      id: id ?? this.id,
      name: name ?? this.name,
      description: description ?? this.description,
      categId: categId ?? this.categId,
      defaultCode: defaultCode ?? this.defaultCode,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
    );
  }

  @override
  String toString() {
    return '''ProductTemplate{
      id: id,
      name: name,
      description: description,
      categId: categId,
      defaultCode: defaultCode,
      createUid: createUid,
      createDate: createDate,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is ProductTemplate &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          name == other.name &&
          description == other.description &&
          categId == other.categId &&
          defaultCode == other.defaultCode &&
          createUid == other.createUid &&
          createDate == other.createDate);

  factory ProductTemplate.fromMap(Map<String, dynamic> map) {
    return new ProductTemplate(
        id: map['id'] != false ? map['id'].toString() as String? : "",
        name: map['name'] != false ? map['name'].toString() as String? : "",
        description: map['description'] != false
            ? map['description'].toString() as String?
            : "",
        categId: map['categ_id'] != false && map['categ_id'] != null
            ? map['categ_id'].toString() as String?
            : "",
        categName: map['categ_id'] != false && map['categ_id'] != null
            ? map['categ_id'][1].toString() as String?
            : "",
        defaultCode: map['default_code'] != false
            ? map['default_code'].toString() as String?
            : "",
        uomId: map['uom_id'] != false && map['uom_id'] != null
            ? map['uom_id'][0].toString() as String?
            : "",
        uomName: map['uom_id'] != false && map['uom_id'] != null
            ? map['uom_id'][1].toString() as String?
            : "",
        density: map['density'] != false ? map['density'] : 0,
        sequence: map['sequence'] != false ? map['sequence'] : 0,
        remark:
            map['remark'] != false ? map['remark'].toString() as String? : "",
        createUid: map['create_uid'] != false && map['create_uid'] != null
            ? map['create_uid'][0].toString() as String?
            : "",
        createName: map['create_uid'] != false && map['create_uid'] != null
            ? map['create_uid'][1].toString() as String?
            : "",
        createDate: map['create_date'] != false
            ? map['create_date'].toString() as String?
            : "",
        writeUid: map['write_uid'] != false && map['write_uid'] != null
            ? map['write_uid'][0].toString() as String?
            : "",
        writeName: map['write_uid'] != false && map['write_uid'] != null
            ? map['write_uid'][1].toString() as String?
            : "",
        writeDate: map['write_date'] != false
            ? map['write_date'].toString() as String?
            : "",
        code: map['ref'] != false ? map['ref'].toString() as String? : '');
  }

  factory ProductTemplate.resFromMap(Map<String, dynamic> map) {
    return new ProductTemplate(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      code: map['ref'] != false ? map['ref'].toString() as String? : "",
      name: map['name'] != false ? map['name'].toString() as String? : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'name': this.name,
      'description': this.description,
      'categId': this.categId,
      'defaultCode': this.defaultCode,
      'createUid': this.createUid,
      'createDate': this.createDate,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.name != null && this.name != '')
        ['name', 'like', '%${this.name}%'],
      if (this.defaultCode != null && this.defaultCode != '')
        ['default_code', 'like', '%${this.defaultCode}%'],
      if (this.description != null && this.description != '')
        ['description', 'like', '%${this.description}%'],
    ];
    // if (list.length == 0) {
    //   list.add(['id', '!=', null]);
    // }
    // ignore: unnecessary_cast
    return list;
  }

  // 板材消耗
  List toConsuDomainList() {
    List list = [
      ['type', '=', "consu"],
      ['categ_id.name', 'like', '%钣金原材料%'],
      if (this.name != null && this.name != '')
        ['name', 'like', '%${this.name}%'],
      if (this.defaultCode != null && this.defaultCode != '')
        ['default_code', '=', this.defaultCode],
    ] as List;
    // if (list.length == 0) {
    //   list.add(['id', '!=', null]);
    // }
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'name': this.name,
      'description': this.description,
      'categ_id': this.categId,
      'default_code': this.defaultCode,
      'create_uid': this.createUid,
      'create_date': this.createDate,
    } as Map<String, dynamic>;
  }

  Map<String, dynamic> toBCOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'name': this.name,
      'density': this.density,
      'sequence': this.sequence,
      this.id == null ? 'code' : 'default_code': this.defaultCode,
      'remark': this.remark,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
